﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Web.Security;

public partial class ReportDE : System.Web.UI.Page
{
    DataView dv = new DataView();
    string reportTitle = "", bTime = "", eTime = "", granu = "", sqlString = "";
    string bYear = "", eYear = "", bMonth = "", eMonth = "", bDay = "", eDay = "";
    string area = "", node = "";
    int chartSignal = 0, reportId;
    protected void Page_Load(object sender, EventArgs e)
    {
        promptLabel.Visible = false;
        int memberId = -1;
        reportId = Convert.ToInt32(Request.QueryString["id"]);
        SqlConnection conn = new SqlConnection(
                    ConfigurationManager.ConnectionStrings["testLottery"].ConnectionString);
        conn.Open();
        string tempSql = "select * from Report where id = " + reportId.ToString();
        SqlCommand tempCmd = new SqlCommand(tempSql, conn);
        SqlDataReader read = tempCmd.ExecuteReader();
        read.Read();
        reportTitle = read.GetValue(1).ToString();
        bTime = read.GetValue(2).ToString();
        eTime = read.GetValue(3).ToString();
        granu = read.GetValue(4).ToString();
        memberId = Convert.ToInt32(read.GetValue(5));
        sqlString = read.GetValue(6).ToString();
        chartSignal = Convert.ToInt32(read.GetValue(7));
        area = read.GetValue(8).ToString();
        node = read.GetValue(9).ToString();
        if (granu == "1")
        {
            bYear = Convert.ToDateTime(bTime).Year.ToString();
            eYear = Convert.ToDateTime(eTime).Year.ToString();
        }
        else if (granu == "2")
        {
            bYear = Convert.ToDateTime(bTime).Year.ToString();
            eYear = Convert.ToDateTime(eTime).Year.ToString();
            bMonth = Convert.ToDateTime(bTime).Month.ToString();
            eMonth = Convert.ToDateTime(eTime).Month.ToString();
        }
        else if (granu == "3")
        {
            bYear = Convert.ToDateTime(bTime).Year.ToString();
            eYear = Convert.ToDateTime(eTime).Year.ToString();
            bMonth = Convert.ToDateTime(bTime).Month.ToString();
            eMonth = Convert.ToDateTime(eTime).Month.ToString();
            bDay = Convert.ToDateTime(bTime).Day.ToString();
            eDay = Convert.ToDateTime(eTime).Day.ToString();
        }
        if (sqlString != null)
        {
            dv = GetData(sqlString).Tables[0].DefaultView;
        }
        else
        {
            dv = GetData().Tables[0].DefaultView;
        }
        if (dv != null)
        {
            GridView1 = dynamicGenerateColumns(GridView1, dv);
            GridView1.DataSource = dv;
            GridView1.AllowPaging = true;
            GridView1.PageSize = 5;
            GridView1.DataBind();
            GridView1.ShowHeader = true;
        }
        else
        {
            GridView1.Visible = false;
            Label1.Text = "无数据";
        }
        ChartGenerate(chartSignal, area);
    }
    //********************************************************************************************
    //*****************funciont name: ChartGenerate(int signal, string area = "")*****************
    //*****************function to generate the chart of the form*********************************
    //*****************signal = (11:same time and group is NO.1, 12:same time and group is NO.2***
    //*************************13:same time and group is NO.3, 21:same node and group is NO.1*****
    //*************************22:same node and group is NO.2, 23:same area and group is NO.3)****
    //*****************area can be used as Area Name or Node ID***********************************
    //*****************node can only be used when signal=22***************************************
    private void ChartGenerate(int signal, string area = "", string node = "")
    {
        //signalLabel.Text = signal.ToString();
        string tempSqlstring = "";
        if (signal == 11)
        { 
            //no need to show the chart
        }
        else if (signal == 12)
        {
            if (granu == "1")
            {
                if (area != "")
                {
                    tempSqlstring = "select node,[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from node_year_lottery_view where area = '" 
                        + area + "' and year = " + bYear;
                    //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + area + "区各站点彩票销售情况";
                    //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                    Chartlet1.XLabels.UnitText = "站点号";
                }
            }
            else if (granu == "2")
            {
                if (area != "")
                {
                    tempSqlstring = "select node,[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from node_month_lottery_view where area = '" 
                        + area + "' and year=" + bYear + " and month=" + bMonth;
                    Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + bMonth + "月" + area + "区各站点彩票销售情况";
                    //chartTitle = "图表:" + bYear + "年" + bMonth + "月" + area + "区各站点彩票销售情况";
                    //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                    Chartlet1.XLabels.UnitText = "站点号";
                }
            }
            else if (granu == "3")
            {
                if (area != "")
                {
                    tempSqlstring = "select node,[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from node_day_lottery_view where area = '"
                        + area + "' and year=" + bYear + " and month=" + bMonth + " and day=" + bDay;
                    //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + bMonth + "月" + bDay + "日" + area + "区各站点彩票销售情况";
                    //chartTitle = "图表:" + bYear + "年" + bMonth + "月" + bDay + "日" + area + "区各站点彩票销售情况";
                    //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                    Chartlet1.XLabels.UnitText = "站点号";
                }
            }
        }
        else if (signal == 13)
        {
            if (granu == "1")
            {
                tempSqlstring = "select area,[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from area_year_lottery_view where year=" + bYear;
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年上海市各区彩票销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "区名";
            }
            else if (granu == "2")
            {
                tempSqlstring = "select area,[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from area_month_lottery_view where year="
                    + bYear + " and month=" + bMonth;
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + bMonth + "月上海市各区彩票销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "区名";
            }
            else if (granu == "3")
            {
                tempSqlstring = "select area,[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from area_day_lottery_view where year="
                    + bYear + " and month=" + bMonth + " and day=" + bDay;
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + bMonth + "月" + bDay + "日上海市各区彩票销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "区名";
            }
        }
        else if (signal == 21)
        {
            if (granu == "1")
            {
                tempSqlstring = "select year,[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from node_year_lottery_view where node='"
                    + area + "' and year between '" + bYear + "' and '" + eYear + "'";
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年至" + eYear + "年" + area + "区" + node + "站点销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "时间";
            }
            else if (granu == "2")
            {
                tempSqlstring = "select CONVERT(varchar,year)+'-'+CONVERT(varchar,month),[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] "
                    + "from node_month_lottery_view where node='" + area + "' and ((year>'" + bYear +
                        "' and year<'" + eYear + "') or (year='" + bYear + "' and year='" + eYear +
                        "' and month>='" + bMonth + "' and month<='" + eMonth + "') or (YEAR='" + bYear + "' and MONTH>='" + bMonth +
                        "') or (YEAR='" + eYear + "' and MONTH<='" + eMonth + "'))";
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + bMonth + "月至" + eYear + "年" + eMonth
                 //   + "月" + area + "区" + node + "站点销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "时间";
            }
            else if (granu == "3")
            {
                tempSqlstring = "select CONVERT(varchar,year)+'-'+CONVERT(varchar,month)+'-'+CONVERT(varchar,day),[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from node_day_lottery_view where node='"
                    + area + "' and ((YEAR>'" + bYear + "' and YEAR<'" + eYear +
                    "') or (YEAR='" + bYear + "' and '" + bYear + "'='" + eYear + "' and ((MONTH>'" + bMonth + "' and MONTH<'" + eMonth +
                    "') or (MONTH='" + bMonth + "' and '" + bMonth + "'='" + eMonth + "' and DAY>='" + bDay + "' and DAY<='" + eDay +
                    "') or (MONTH='" + bMonth + "' and '" + bMonth + "'!='" + eMonth + "' and day>='" + bDay + "') or (month='" + eMonth +
                    "' and '" + bMonth + "'!='" + eMonth + "' and DAY<='" + eDay + "'))) or (YEAR='" + bYear + "' and '" + bYear + "'!='" + eYear +
                    "' and ((MONTH>'" + bMonth + "') or (MONTH='" + bMonth + "' and DAY>='" + bDay + "'))) or (YEAR='" + eYear +
                    "' and '" + bYear + "'!='" + eYear + "' and ((MONTH<'" + eMonth + "') or (MONTH='" + eMonth + "' and DAY<='" + eDay + "'))))";
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + bMonth + "月" + bDay + "日至" + eYear + "年" + eMonth + "月" + eDay
                //    + "日" + area + "区" + node + "站点销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "时间";
            }
        }
        else if (signal == 22)
        {
            if (granu == "1")
            {
                tempSqlstring = "select year,[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from node_year_lottery_view where area='"
                    + area + "' and node='" + node + "' and year between '" + bYear + "' and '" + eYear + "'";
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年至" + eYear + "年" + area + "区" + node + "站点销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "时间";
            }
            else if (granu == "2")
            {
                tempSqlstring = "select CONVERT(varchar,year)+'-'+CONVERT(varchar,month),[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] "
                    + "from node_month_lottery_view where area='" + area + "' and node='" + node + "' and ((year>'" + bYear +
                        "' and year<'" + eYear + "') or (year='" + bYear + "' and year='" + eYear +
                        "' and month>='" + bMonth + "' and month<='" + eMonth + "') or (YEAR='" + bYear + "' and MONTH>='" + bMonth +
                        "') or (YEAR='" + eYear + "' and MONTH<='" + eMonth + "'))";
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + bMonth + "月至" + eYear + "年" + eMonth
                //    + "月" + area + "区" + node + "站点销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "时间";
            }
            else if (granu == "3")
            {
                tempSqlstring = "select CONVERT(varchar,year)+'-'+CONVERT(varchar,month)+'-'+CONVERT(varchar,day),[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from node_day_lottery_view where area='"
                    + area + "' and node='" + node + "' and ((YEAR>'" + bYear + "' and YEAR<'" + eYear +
                    "') or (YEAR='" + bYear + "' and '" + bYear + "'='" + eYear + "' and ((MONTH>'" + bMonth + "' and MONTH<'" + eMonth +
                    "') or (MONTH='" + bMonth + "' and '" + bMonth + "'='" + eMonth + "' and DAY>='" + bDay + "' and DAY<='" + eDay +
                    "') or (MONTH='" + bMonth + "' and '" + bMonth + "'!='" + eMonth + "' and day>='" + bDay + "') or (month='" + eMonth +
                    "' and '" + bMonth + "'!='" + eMonth + "' and DAY<='" + eDay + "'))) or (YEAR='" + bYear + "' and '" + bYear + "'!='" + eYear +
                    "' and ((MONTH>'" + bMonth + "') or (MONTH='" + bMonth + "' and DAY>='" + bDay + "'))) or (YEAR='" + eYear +
                    "' and '" + bYear + "'!='" + eYear + "' and ((MONTH<'" + eMonth + "') or (MONTH='" + eMonth + "' and DAY<='" + eDay + "'))))";
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + bMonth + "月" + bDay + "日至" + eYear + "年" + eMonth + "月" + eDay
                //    + "日" + area + "区" + node + "站点销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "时间";
            }
        }
        else if (signal == 23)
        {
            if (granu == "1")
            {
                tempSqlstring = "select year,[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] from area_year_lottery_view where area='" 
                    + area + "' and year between '" + bYear + "' and '" + eYear + "'";
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年至" + eYear + "年" + area + "区各站点销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "时间";
            }
            else if (granu == "2")
            {
                tempSqlstring = "select CONVERT(varchar,year)+'-'+CONVERT(varchar,month),[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] "
                    + "from area_month_lottery_view where area='" + area + "' and ((year>'" + bYear +
                        "' and year<'" + eYear + "') or (year='" + bYear + "' and year='" + eYear +
                        "' and month>='" + bMonth + "' and month<='" + eMonth + "') or (YEAR='" + bYear + "' and MONTH>='" + bMonth +
                        "') or (YEAR='" + eYear + "' and MONTH<='" + eMonth + "'))";
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + bMonth + "月至" + eYear + "年" + eMonth
                //    + "月" + area + "区各站点销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "时间";
            }
            else if (granu == "3")
            {
                tempSqlstring = "select CONVERT(varchar,year)+'-'+CONVERT(varchar,month)+'-'+CONVERT(varchar,day),[双色球],[福彩3D],[七乐彩],[东方6+1],[15选5],[天天彩选4],[时时乐] "
                    + "from area_day_lottery_view where area='" + area + "' and ((YEAR>'" + bYear + "' and YEAR<'" + eYear +
                    "') or (YEAR='" + bYear + "' and '" + bYear + "'='" + eYear + "' and ((MONTH>'" + bMonth + "' and MONTH<'" + eMonth +
                    "') or (MONTH='" + bMonth + "' and '" + bMonth + "'='" + eMonth + "' and DAY>='" + bDay + "' and DAY<='" + eDay +
                    "') or (MONTH='" + bMonth + "' and '" + bMonth + "'!='" + eMonth + "' and day>='" + bDay + "') or (month='" + eMonth +
                    "' and '" + bMonth + "'!='" + eMonth + "' and DAY<='" + eDay + "'))) or (YEAR='" + bYear + "' and '" + bYear + "'!='" + eYear +
                    "' and ((MONTH>'" + bMonth + "') or (MONTH='" + bMonth + "' and DAY>='" + bDay + "'))) or (YEAR='" + eYear +
                    "' and '" + bYear + "'!='" + eYear + "' and ((MONTH<'" + eMonth + "') or (MONTH='" + eMonth + "' and DAY<='" + eDay + "'))))";
                //Chartlet1.ChartTitle.Text = "图表:" + bYear + "年" + bMonth + "月" + bDay + "日至" + eYear + "年" + eMonth + "月" + eDay
                //    + "日" + area + "区各站点销售情况";
                //chartTitleLabel.Text = Chartlet1.ChartTitle.Text;
                Chartlet1.XLabels.UnitText = "时间";
            }
        }
        if (tempSqlstring != "")
        {
            //signalLabel.Text = signal.ToString();
            Chartlet1.BindChartData(GetData(tempSqlstring));
            Chartlet1.YLabels.UnitText = "张数";
        }
    }
    //*******************************************************************************************************************************

    private DataTable ColRowReverse(DataTable dt)
    {
        DataTable dtNew = new DataTable();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dtNew.Columns.Add("Col" + (i + 1).ToString(), typeof(string));
        }
        foreach (DataColumn dc in dt.Columns)
        {
            DataRow drNew = dtNew.NewRow();
            drNew["ColumnName"] = dc.ColumnName;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                drNew[i + 1] = dt.Rows[i][dc].ToString();
            }
            dtNew.Rows.Add(drNew);
        }
        return dtNew;
    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        string sortExpression = e.SortExpression;
        for (int i = 0; i < GridView1.Columns.Count; i++)
        {
            GridView1.Columns[i].Visible = true; 
        }
        if (GridViewSortDirection == SortDirection.Ascending)
        {
            GridViewSortDirection = SortDirection.Descending;
            SortGridView(sortExpression, "DESC");
        }
        else
        {
            GridViewSortDirection = SortDirection.Ascending;
            SortGridView(sortExpression, "ASC");
        }
        //string name;
        //for (int i = 1; i <= GridView1.Columns.Count; i++)
        //{
        //    name = "cb" + i.ToString();
        //    CheckBox tpcb = (CheckBox)Panel1.FindControl(name);
        //    if (!tpcb.Checked)
        //    {
        //        GridView1.Columns[i - 1].Visible = false;
        //    }
        //}
    }

    public SortDirection GridViewSortDirection
    {
        get
        {
            if (ViewState["sortDirection"] == null)
                ViewState["sortDirection"] = SortDirection.Descending;
            return (SortDirection)ViewState["sortDirection"];
        }
        set { ViewState["sortDirection"] = value; }
    }
    private void SortGridView(string sortExpression, string direction)
    {
        DataTable dt = GetData(sqlString).Tables[0];
        dv = dt.DefaultView;
        dv.Sort = sortExpression + " "+ direction;
        GridView1.DataSource = dv;
        GridView1.DataBind();
    }

    
    private DataSet GetData(string sql = "")
    {
        SqlConnection conn = new SqlConnection(
        ConfigurationManager.ConnectionStrings["testLottery"].ConnectionString);
        conn.Open();
        if (sql == "" || sql == null)
        {
            if ((int)Session["group"] == 3)
            {
                sql = "select * from area_year_lottery_view where year = " + ((int)DateTime.Now.Year - 1).ToString();
            }
            else if ((int)Session["group"] == 2)
            {
                string tempSql = "select name from Area,AreaManager where Area.id=AreaManager.area and AreaManager.member=" + Session["uid"].ToString();
                SqlCommand tempCmd = new SqlCommand(tempSql,conn);
                SqlDataReader read = tempCmd.ExecuteReader();
                read.Read();
                string areaName = read.GetValue(0).ToString();
                sql = "select * from node_year_lottery_view where year = " + ((int)DateTime.Now.Year - 1).ToString() + " and area = '" + areaName + "'";
            }
        }
        conn.Close();
        conn.Open();
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sql, conn);
        SqlCommand cmd = new SqlCommand(sql, conn);
        da.Fill(ds);
        return ds;
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = dv;
        GridView1.DataBind();
        //for (int i = 1; i < Panel2.Controls.Count; i++)
        //{
        //    this.RemovedControl(Panel2.FindControl("bt" + i));
        //    Panel2.FindControl("bt" + i).Visible = false;
        //}
        Button bt;
        //for (int j = 1; j <= GridView1.Rows.Count; j++)
        //{
        //    //GridView1.selec
        //    bt = new Button();
        //    bt.ID = "bt" + j.ToString();
        //    bt.CssClass = "areabt";
        //    bt.Text = GridView1.Rows[j - 1].Cells[0].Text;
        //    bt.Click += new EventHandler(areabt_Click);
        //    Panel2.Controls.Add(bt);
        //}
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        for(int i = 0; i < 5; i++)
            GridView1.Rows[i].Cells[0].Visible = false;
        GridView1.HeaderRow.Cells[0].Visible = false;
    }
    protected void areabt_Click(object sender, EventArgs e)
    {
        Button currentButton = (Button)sender;
        //condition = currentButton.Text;
        //for (int i = 1; i < Panel1.Controls.Count; i++)
        //{
        //    this.RemovedControl(Panel1.FindControl("cb" + i));
        //    Panel1.FindControl("cb" + i).Visible = false;
        //}
        //for (int i = 1; i < Panel2.Controls.Count; i++)
        //{
        //    this.RemovedControl(Panel2.FindControl("bt" + i));
        //    Panel2.FindControl("bt" + i).Visible = false;
        //}
        //this.Page_Load(this,null);
        if ((int)Session["group"] == 1)
        {
            chartSignal = 21;
            ChartGenerate(21, currentButton.Text);
        }
        else if ((int)Session["group"] == 2)
        {
            SqlConnection conn = new SqlConnection(
                    ConfigurationManager.ConnectionStrings["testLottery"].ConnectionString);
            conn.Open();
            string tempSql = "select name from Area,AreaManager where Area.id=AreaManager.area and AreaManager.member=" + Session["uid"].ToString();
            SqlCommand tempCmd = new SqlCommand(tempSql,conn);
            SqlDataReader read = tempCmd.ExecuteReader();
            read.Read();
            string areaName = read.GetValue(0).ToString();
            chartSignal = 22;
            ChartGenerate(22, areaName, currentButton.Text);
        }
        else if ((int)Session["group"] == 3)
        {
            chartSignal = 23;
            ChartGenerate(23, currentButton.Text);
        }
    }
    public static GridView dynamicGenerateColumns(GridView gv, DataView dv)
    {
        // 把GridView的自动产生列设置为false,否则会出现重复列
        gv.AutoGenerateColumns = false;

        // 清空所有的Columns
        gv.Columns.Clear();
        //gv.Columns[0].ControlStyle.Width = 100;
        // 遍历DataTable 的每个Columns,然后添加到GridView中去 
        //gv.Width = 400;
        foreach (DataColumn item in dv.Table.Columns)
        {
            BoundField col = new BoundField();
            col.HeaderText = item.ColumnName;
            col.DataField = item.ColumnName;
            col.SortExpression = item.ColumnName;
            col.Visible = true;
            gv.Columns.Add(col);
        }
        return gv;
    }
    public void cb_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox cb = (CheckBox)sender;
        int index = Convert.ToInt32(cb.ID.Substring(2)) - 1;
        if (!cb.Checked)
        {
            GridView1.Columns[index].Visible = false;
        }
        else
        {
            GridView1.Columns[index].Visible = true;
            dv = GetData().Tables[0].DefaultView;
        }
    }
    protected void deleteButton_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(
                    ConfigurationManager.ConnectionStrings["testLottery"].ConnectionString);
        conn.Open();
        string tempSql = "delete from Report where id =" + reportId.ToString();
        SqlCommand tempCmd = new SqlCommand(tempSql, conn);
        int rowNum = tempCmd.ExecuteNonQuery();
        if (rowNum == 1)
        {
            //Response.Write("<script language='javascript'>alert('删除成功！');window.location='ReportRD.aspx'</script>");
            promptLabel.Visible = true;
            promptLabel.Text = "删除成功！";
            Response.Redirect("ReportRD.aspx");
        }
        else
        {
            //Response.Write("<script language='javascript'>alert('删除失败！')</script>");
            promptLabel.Visible = true;
            promptLabel.Text = "删除失败！";
            Response.Redirect("ReportRD.aspx");
        }
        conn.Close();
    }
}




